package states;

import model.Assets;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import controller.Game;
import controller.Global;

public class Load extends BasicGameState {
	private int id;
	private boolean done;

	public Load(int id) {
		this.id = id;
		done = false;
	}

	@Override
	public int getID() {
		return id;
	}

	@Override
	public void init(GameContainer arg0, StateBasedGame arg1)
			throws SlickException {
	}

	@Override
	public void enter(GameContainer container, StateBasedGame game)
			throws SlickException {

		super.enter(container, game);
		
		// load assets
		Assets.getInstance().loadAssets();

		// play music
		Assets.getInstance().getMusic("assets/music/music.ogg").loop();

		done = true;
	}

	@Override
	public void render(GameContainer arg0, StateBasedGame arg1, Graphics arg2)
			throws SlickException {

		arg2.drawString("Loading Game...", (Global.screenX / 2) - 100,
				Global.screenY / 2);

	}

	@Override
	public void update(GameContainer arg0, StateBasedGame arg1, int arg2)
			throws SlickException {
		if (done) {
			arg1.enterState(Game.States.PLAYSTATE.ordinal(), null, null);
		}
	}
}
